###
navigation

Stockée dans window.

Méthodes:
	navigation.setup
	navigation.prev
	navigation.next

	navigation.display(nom_de_la_vue)
	navigation.next_view()
	navigation.prev_view()
	navigation.setup_view()

	navigation.set_clicks(nom_de_la_vue)
	navigation.next_clicks()
	navigation.prev_clicks()
	navigation.setup_clicks()
	navigation.reset_clicks()

Propriétés
	navigation.views.active
	navigation.views.sequence
	navigation.views.all

	navigation.clicks


Système de navigation entre zones d'affichage.
Utilise jQuery

Elements sur lesquels on ecoute le click:
	#moss_return
	#validate
	.card
	.card .data
	.edit_section tr
	eventuellement un bouton start plus tard...

Les conséquences du clic sont gérées
en fonction d'une variable globale
comprenant l'etat de l'affichage parmi:
	splash_screen
	dashboard
	crva_view
	crva_edit
	crme_view
	crme_edit

@variable_globale window.app_state


Les éléments constituant le layout sont:
	#page0: @splash_screen
	#page1: @dashboard
		#top_panel
		#crva_list_widgets_container
	#page2: @crva_view
		#top_panel_crva
		#flight_widgets_container
		#edit_panel
			.edit_panel_slides_wrapper @crva_edit
			#crme_cards_wrapper
				#crme_cards @crme_view
				#crme_edit @crme_edit


Les différentes sections voient leur CSS modifiés en fonction
de l'etat de l'application. Voici comment:
###

###
La navigation se fait au travers d'éléments
etant en attente d'un clic. Ces bind sont modifiés
en fonction du view state courant.
###

###
 TODO: Factoriser
###

navigation = {

	display: ( view_name)->
		console.log('setting view '+view_name)
		this.views.all[view_name]()
		this.set_clicks( view_name)

	set_clicks: (view_name)->
		this.reset_clicks()
		this.clicks[view_name]()

	setup:()->
		this.setup_view()
		this.setup_clicks()

	prev: ()->
		actual = this.views.sequence.indexOf( this.views.active)
		if actual > 0
			this.views.active = this.views.sequence[actual-1]
			this.display( this.views.active)
		else
			console.warn("Première vue affichée")

	next: ()->
		actual = this.views.sequence.indexOf( this.views.active)
		if actual < ( this.views.sequence.length - 1 )
			this.views.active =  this.views.sequence[actual+1]
			this.display( this.views.active)
		else
			console.warn("Dernière vue affichée")

	setup_view: ()->
		this.display( this.views.active)

	setup_clicks: ()->
		this.set_clicks( this.views.active)

	views:
		active: 'dashboard'
		sequence:  ['splash_screen','dashboard','crva_view','crva_edit','crme_view','crme_edit']
		all:
			splash_screen : ()->
				$('#page0').show()
				$('#page1').hide()
				$('#page2').hide()

			dashboard : ()->
				$('#page0').hide()
				$('#page1').show()
				$('#page2').hide()
				try
					crvapp.crvaDetails.getBackToDashboard()
				catch
					""

			crva_view : ()->
				$('#page0').hide()
				$('#page1').hide()
				$('#validate').hide()
				$('#page2').show()
				$('#flight_widgets_container').removeClass('semifold')
				$('#edit_panel').addClass('fold')
				$('#crme_edit').addClass('fold')

			crva_edit : ()->
				crvapp.crvaDetails.loadValuesForEdit()
				$('#page0').hide()
				$('#page1').hide()
				$('#page2').show()
				$('#validate').show()
				$('#flight_widgets_container').addClass('semifold')
				$('#flight_widgets_container').removeClass('fold')
				$('#edit_panel').removeClass('fold')
				$('#edit_panel').removeClass('unfold')
				$('.edit_panel_slides_wrapper').removeClass('fold')
				$('#crme_cards_wrapper').addClass('fold')
				$('#crme_edit').addClass('fold')
				$('#crme_cards').addClass('fold')

			crme_view : ()->
				$('#page0').hide()
				$('#page1').hide()
				$('#page2').show()
				$('#flight_widgets_container').addClass('fold')
				$('#edit_panel').removeClass('fold')
				$('#edit_panel').addClass('unfold')
				$('.edit_panel_slides_wrapper').addClass('fold')
				$('#crme_cards_wrapper').removeClass('fold')
				$('#crme_cards').removeClass('fold')
				$('#crme_cards').removeClass('semifold')
				$('#crme_edit').addClass('fold')

			crme_edit : ()->
				$('#page0').hide()
				$('#page1').hide()
				$('#page2').show()
				$('#flight_widgets_container').addClass('fold')
				$('#edit_panel').removeClass('fold')
				$('.edit_panel_slides_wrapper').addClass('fold')
				$('#crme_cards').addClass('semifold')
				$('#crme_edit').removeClass('fold')
				
			
	reset_clicks: ()->
		$(	'#addFlight, #moss_return, #validate, #start, #crva_list_tbody tr, .card, .card .data, #flight_widgets_container, .edit_panel_slides_wrapper, #crme_view tr, .edit_section tr, #mini_logo').off('click.navigation')

	clicks:
		splash_screen: ()->
			$('#next_dev, #start').on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.next()

		dashboard: ()->
			$('#prev_dev, #moss_return, #mini_logo').on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.prev()
			$('#next_dev, #crva_list_tbody tr, #addFlight'	).on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.next()

		crva_view: ()->
			$('#prev_dev, #moss_return, #validate'	).on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.prev()
			$('#next_dev, .card').on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.next()

		crva_edit: ()->
			$('#prev_dev, #moss_return').on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.prev()
			$('#next_dev, #crme_list_container tr').on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.next()

		crme_view: ()->
			$('#prev_dev, #moss_return, #validate, #flight_widgets_container, .edit_panel_slides_wrapper').on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.prev()
			$('#next_dev, #crme_cards .card').on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.next()

		crme_edit: ()->
			$('#prev_dev, #moss_return, #validate, #crme_cards .card, .edit_panel_slides_wrapper').on 'click.navigation',(e)->
				e.stopPropagation()
				window.navigation.prev()
}

window.navigation = navigation
window.navigation.setup()